---
title: "Table A.4"
output: 
---

# Table A.4

# Who's to Blame? Postconflict Violence and Public Attitudes Towards Peace Agreements
# Wyer, Frank. 

#clear environment
```{r clear environment}
rm(list = ls())
```

# uncomment and set working directory to replication archive
# setwd("~/blame_replication")

# Uncomment to install packages if necessary
# install.packages("tidyverse")
# install.packages("texreg")
# install.packages("estimatr")


#load packages
```{r}
library(tidyverse)
library(estimatr)
library(texreg)
```

#read in data
```{r}
survey_clean <- read.csv("survey_clean.csv")
```

#create binary variables for security trajectory and political engagement
```{r generate binary variables}
survey_clean <- survey_clean %>% 
  mutate(homs_worse = ifelse(homratediff > 0, 1, 0), 
         high_engage = ifelse(engage_zscale > median(engage_zscale), 1, 0))
```

#estimate models in control group 
```{r estimate models}
eln_het_controls <- lm_robust(formula = eln_scale ~ Q25 + factor(farc_presence == 1) + factor(high_engage == 1) + factor(homs_worse == 1), se_type = "HC2", data = survey_clean %>% filter(treatment == "C"), alpha = .05)

accords_het_controls <- lm_robust(formula = accords_scale ~ Q25 + factor(farc_presence == 1) + factor(high_engage == 1) + factor(homs_worse == 1), se_type = "HC2", data = survey_clean %>% filter(treatment == "C"), alpha = .05)

dissident_het_controls <- lm_robust(dissident_scale ~ Q25 + factor(farc_presence == 1) + factor(high_engage == 1) + factor(homs_worse == 1), se_type = "HC2", data = survey_clean %>% filter(treatment == "C"), alpha = .05)

index_het_controls <- lm_robust(outcomes_zscale ~ Q25 + factor(farc_presence == 1) + factor(high_engage == 1) + factor(homs_worse == 1), se_type = "HC2", data = survey_clean %>% filter(treatment == "C"), alpha = .05)
```

#gnerate table for results
```{r generate results table}
texreg(list(eln_het_controls, dissident_het_controls, accords_het_controls, index_het_controls), custom.coef.map = list("(Intercept)" = "(Intercept)", "Q25" = "Ideology (L = 1; R = 6)", "factor(high_engage == 1)TRUE" = "High Political Engagement", "factor(homs_worse == 1)TRUE" = "Security Trajectory Worse", "factor(farc_presence == 1)TRUE" = "FARC Presence"), digits = 2, include.ci = FALSE, single.row = FALSE, include.fstatistic = FALSE, include.rmse = FALSE, include.rsquared = FALSE, include.adjrs = FALSE, include.nobs = TRUE, stars = numeric(0), float.pos = "h", caption.above	= TRUE, caption = "Baseline Heterogeneity in Control Group")
```
